<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html >
<html>
	<head>
		<%@ include file="/common/taglibs.jsp"%>
		<title>sinlog</title>
	</head>
	<body>
	<div class="mainContent">
		<div class="editDiv">
			<div class="editHead">
				<c:if test="${method == 'add'}">
					<span>新增任务</span>
				</c:if>
				<c:if test="${method == 'view'}">
					<span>查看任务</span>
				</c:if>
			</div>
			<form class="editForm" action="#" method="post">
				<input type="hidden" name="task.taskId" value="${task.taskId}"/>
				<input type="hidden" name="task.accountId" value="${task.accountId}"/>
				<input type="hidden" name="method" value="${method}"/>
				<table width="100%">
					<tr>
						<td align="right">任务名：</td>
						<td><input type="text" name="task.taskName" value="${task.taskName}" class="validate[required]"
							<c:if test="${method == 'edit'}">
								 readonly="readonly"
							</c:if>/>
						</td>
					</tr>
					<tr>
						<td align="right">应用名：</td>
						<td>
							<input type="hidden" name="task.appId" id="appId"/>
							<input id="appName" type="text" name="task.appName" value="${task.appName}" class="validate[required]"/>
						</td>
					</tr>
					<tr>
						<td align="right">接口类型：</td>
						<td>
							<sl:paramSelect name="task.taskType" paramType="<%=SinlogConstants.TASK_TYPE%>" id="" value="${task.taskType}" style="width:100px"/>
						</td>
					</tr>
					<tr>
						<td align="right">关键字：</td>
						<td>
							<textarea name="task.contentKey" class="validate[required]" style="resize: none;width: 500px;" cols="45" rows="5">${task.contentKey}</textarea>
							<img src="${tip}" class="ttip" title="正则表达式"/>
						</td>
					</tr>
					<tr>
						<td align="right">CLASS：</td>
						<td><input type="text" name="task.classKey" value="com.szf.task.service.api.tencent.AreaTimeline" class="validate[required]" style="width: 350px;"/></td>
					</tr>
					<tr>
						<td align="right">参数：</td>
						<td>
							<textarea name="task.param" style="resize: none;width: 500px;" cols="45" rows="2">${task.param}</textarea>
							<img src="${tip}" class="ttip" title="任务参数，格式name=val;"/>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<c:if test="${method != 'view'}">
								<a href="javascript:doSubmit();" class="button blue">提交</a>
							</c:if>
							<a href="javascript:doReturn();" class="button">返回</a>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
<script type="text/javascript">
	$(document).ready(function(){
		$('.ttip').tooltip({position: "right"});
		jQuery(".editForm").validationEngine();
		
		var method = '${method}';
		if('add' == method){
			Util.doAjaxPost('${ctx}/task!getUseAppInfo.action',null,function(text){
				var ret = jQuery.parseJSON(text);
				$("#appName").autocomplete(ret, {
					width: 310,
					matchContains: true,
					autoFill: false,
					formatItem: function(row, i, max) {
						return row.appName;
					},
					formatMatch: function(row, i, max) {
						return row.appName;
					},
					formatResult: function(row) {
						return row.appName;
					}
				});
				$("#appName").result(function(el,r,v){
					$('#appId').val(r.appId);
					$('#appName').val(r.appName);
				});
			});
		}
		
	});
	function doSubmit(){
		var vali = $(".editForm").validationEngine('validate');
		if(!vali){
			return;
		}
		var appId = $('#appId').val();
		if(appId == ''){
			$.messager.alert('系统提示','该应用不存在或已被使用！','error');
			return;
		}
		var data = $('.editForm').serialize();
		wait();
		Util.doAjaxPost('${ctx}/task!update.action',data,function(text){
			uwait();
			var ret = jQuery.parseJSON(text);
			if(ret.success){
				$.messager.confirm('系统提示','操作成功，是否现在返回列表？',function(r){
					if(r){
						openMenu('任务管理','${ctx}/task.action');
					}
				});
			}else{
				$.messager.alert('系统提示',ret.msg,'error');
			}
			
		});
	}
	function doReturn(){
		openMenu('任务管理','${ctx}/task.action');
	}

</script>
	</body>
</html>